/*
 * Copyright (c) 2022-2023 cetcclout Co., Ltd All rights reserved.
 * Sensor Adapter is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package com.cetccloud.cimp.common.util;
import cn.hutool.json.JSONUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @apiNote 废水模拟数据
 */
public class WasteWaterCreator {
	
	private static final Logger log = LoggerFactory.getLogger(WasteWaterCreator.class);
	
    private static String getCellValue(Object sValue){
        String value = sValue.toString()+"";
        if(value.contains(".")) {
            String data = String.format("%.3f", Double.valueOf(value));
            return data;
        }else{
            return value;
        }
    }

    /**
     化学需氧量实时浓度(mg/L)     w01018-Rtd
     化学需氧量实时折算浓度(mg/L)  w01018-ZsRtd
     氨氮实时浓度(mg/L)          w21003-Rtd
     氨氮实时折算浓度(mg/L)       w21003-ZsRtd
     总磷实时数据(mg/L)          w21011-Rtd
     总磷实时折算浓度(mg/L)       w21011-ZsRtd
     总氮实时浓度(mg/L)          w21001-Rtd
     总氮实时折算浓度(mg/L)       w21001-ZsRtd
     PH值实时数据(无量纲)        w01001-Rtd
     废水流量实时数据(m3/h)      c060605-Rtd
     化学需氧量排放量（kg）       c060601-Rtd
     氨氮排放量（kg）           c060602-Rtd
     总磷排放量（kg）           c060603-Rtd
     总氮排放量（kg）           c060604-Rtd
     ======================================
     * @param deviceId
     * @param dataBlock
     * @param randomData
     */
    public static void createWasteWaterRtdData(String deviceId, StringBuilder dataBlock, Map<String, Object> randomData) {
        //1-化学需氧量实时浓度(mg/L)     w01018-Rtd
        //2-化学需氧量实时折算浓度(mg/L)  w01018-ZsRtd
        dataBlock.append("w01018-Rtd="+ getCellValue(randomData.get("化学需氧量实时浓度(mg/L)")) +",w01018-ZsRtd="+ getCellValue(randomData.get("化学需氧量实时折算浓度(mg/L)"))+",w01018-Flag=N;");
        //3-氨氮实时浓度(mg/L)          w21003-Rtd
        //4-氨氮实时折算浓度(mg/L)       w21003-ZsRtd
        dataBlock.append("w21003-Rtd="+ getCellValue(randomData.get("氨氮实时浓度(mg/L)")) +",w21003-ZsRtd="+ getCellValue(randomData.get("氨氮实时折算浓度(mg/L)"))+",w21003-Flag=N;");
        //5-总磷实时数据(mg/L)          w21011-Rtd
        //6-总磷实时折算浓度(mg/L)       w21011-ZsRtd
        dataBlock.append("w21011-Rtd="+ getCellValue(randomData.get("总磷实时数据(mg/L)")) +",w21011-ZsRtd="+ getCellValue(randomData.get("总磷实时折算浓度(mg/L)"))+",w21011-Flag=N;");
        //7-总氮实时浓度(mg/L)          w21001-Rtd
        //8-总氮实时折算浓度(mg/L)       w21001-ZsRtd
        dataBlock.append("w21001-Rtd="+ getCellValue(randomData.get("总氮实时浓度(mg/L)")) +",w21001-ZsRtd="+ getCellValue(randomData.get("总氮实时折算浓度(mg/L)"))+",w21001-Flag=N;");

        //9-PH值实时数据(无量纲)  w01001
        dataBlock.append("w01001-Rtd="+ getCellValue(randomData.get("PH值实时数据(无量纲)")) +",w01001-Flag=N;");
        //10-废水流量实时数据(m3/h)  c060605
        dataBlock.append("c060605-Rtd="+ getCellValue(randomData.get("废水流量实时数据(m3/h)")) +",c060605-Flag=N;");
        //11-化学需氧量排放量（kg）  c060601
        dataBlock.append("c060601-Rtd="+ getCellValue(randomData.get("化学需氧量排放量（kg）")) +",c060601-Flag=N;");
        //12-氨氮排放量（kg）       c060602
        dataBlock.append("c060602-Rtd="+ getCellValue(randomData.get("氨氮排放量（kg）")) +",c060602-Flag=N;");
        //13-总磷排放量（kg）       c060603
        dataBlock.append("c060603-Rtd="+ getCellValue(randomData.get("总磷排放量（kg）")) +",c060603-Flag=N;");
        //14-总氮排放量（kg）        c060604
        dataBlock.append("c060604-Rtd="+ getCellValue(randomData.get("总氮排放量（kg）")) +",c060604-Flag=N");
        //========================
        //1-化学需氧量实时浓度(mg/L)  w01018
        List<Double> w01018Rtd = DataConfig.MINUTE_DATA.get(deviceId,"w01018-Rtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"w01018-Rtd");
        w01018Rtd.add(Double.valueOf(getCellValue(randomData.get("化学需氧量实时浓度(mg/L)").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "w01018-Rtd", w01018Rtd);
        //2-化学需氧量实时折算浓度(mg/L)  w01018
        List<Double> w01018ZsRtd = DataConfig.MINUTE_DATA.get(deviceId,"w01018-ZsRtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"w01018-ZsRtd");
        w01018ZsRtd.add(Double.valueOf(getCellValue(randomData.get("化学需氧量实时浓度(mg/L)").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "w01018-ZsRtd", w01018ZsRtd);

        //3-氨氮实时浓度(mg/L)     w21003
        List<Double> w21003Rtd = DataConfig.MINUTE_DATA.get(deviceId,"w21003-Rtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"w21003-Rtd");
        w21003Rtd.add(Double.valueOf(getCellValue(randomData.get("氨氮实时浓度(mg/L)").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "w21003-Rtd", w21003Rtd);
        //4-氨氮实时折算浓度(mg/L) w21003
        List<Double> w21003ZsRtd = DataConfig.MINUTE_DATA.get(deviceId,"w21003-ZsRtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"w21003-ZsRtd");
        w21003ZsRtd.add(Double.valueOf(getCellValue(randomData.get("氨氮实时折算浓度(mg/L)").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "w21003-ZsRtd", w21003ZsRtd);

        //5-总磷实时数据(mg/L)    w21011
        List<Double> w21011Rtd = DataConfig.MINUTE_DATA.get(deviceId,"w21011-Rtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"w21011-Rtd");
        w21011Rtd.add(Double.valueOf(getCellValue(randomData.get("总磷实时数据(mg/L)").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "w21011-Rtd", w21011Rtd);

        //6-总磷实时折算浓度(mg/L)    w21011
        List<Double> w21011ZsRtd = DataConfig.MINUTE_DATA.get(deviceId,"w21011-ZsRtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"w21011-ZsRtd");
        w21011ZsRtd.add(Double.valueOf(getCellValue(randomData.get("总磷实时折算浓度(mg/L)").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "w21011-ZsRtd", w21011ZsRtd);

        //7-总氮实时浓度(mg/L)    w21001
        List<Double> w21001Rtd = DataConfig.MINUTE_DATA.get(deviceId,"w21001-Rtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"w21001-Rtd");
        w21001Rtd.add(Double.valueOf(getCellValue(randomData.get("总氮实时浓度(mg/L)").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "w21001-Rtd", w21001Rtd);
        //8-总氮实时折算浓度(mg/L)    w21001
        List<Double> w21001ZsRtd = DataConfig.MINUTE_DATA.get(deviceId,"w21001-ZsRtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"w21001-ZsRtd");
        w21001ZsRtd.add(Double.valueOf(getCellValue(randomData.get("总氮实时折算浓度(mg/L)").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "w21001-ZsRtd", w21001ZsRtd);


        //9-PH值实时数据(无量纲)  w01001
        List<Double> w01001Rtd = DataConfig.MINUTE_DATA.get(deviceId,"w01001-Rtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"w01001-Rtd");
        w01001Rtd.add(Double.valueOf(getCellValue(randomData.get("PH值实时数据(无量纲)").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "w01001-Rtd", w01001Rtd);


        //10-废水流量实时数据(m3/h)  c060605
        List<Double> c060605Rtd = DataConfig.MINUTE_DATA.get(deviceId,"c060605-Rtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"c060605-Rtd");
        c060605Rtd.add(Double.valueOf(getCellValue(randomData.get("废水流量实时数据(m3/h)").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "c060605-Rtd", c060605Rtd);
        //11-化学需氧量排放量（kg）  c060601
        List<Double> c060601Rtd = DataConfig.MINUTE_DATA.get(deviceId,"c060601-Rtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"c060601-Rtd");
        c060601Rtd.add(Double.valueOf(getCellValue(randomData.get("化学需氧量排放量（kg）").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "c060601-Rtd", c060601Rtd);
        //12-氨氮排放量（kg）       c060602
        List<Double> c060602Rtd = DataConfig.MINUTE_DATA.get(deviceId,"c060602-Rtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"c060602-Rtd");
        c060602Rtd.add(Double.valueOf(getCellValue(randomData.get("氨氮排放量（kg）").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "c060602-Rtd", c060602Rtd);

        //13-总磷排放量（kg）       c060603
        List<Double> c060603Rtd = DataConfig.MINUTE_DATA.get(deviceId,"c060603-Rtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"c060603-Rtd");
        c060603Rtd.add(Double.valueOf(getCellValue(randomData.get("总磷排放量（kg）").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "c060603-Rtd", c060603Rtd);
        //14-总氮排放量（kg）        c060604
        List<Double> c060604Rtd = DataConfig.MINUTE_DATA.get(deviceId,"c060604-Rtd")==null?new ArrayList<>():DataConfig.MINUTE_DATA.get(deviceId,"c060604-Rtd");
        c060604Rtd.add(Double.valueOf(getCellValue(randomData.get("总氮排放量（kg）").toString())));
        DataConfig.MINUTE_DATA.put(deviceId, "c060604-Rtd", c060604Rtd);

    }

    /**
     化学需氧量实时浓度(mg/L)     w01018-Rtd
     化学需氧量实时折算浓度(mg/L)  w01018-ZsRtd

     氨氮实时浓度(mg/L)          w21003-Rtd
     氨氮实时折算浓度(mg/L)       w21003-ZsRtd

     总磷实时数据(mg/L)          w21011-Rtd
     总磷实时折算浓度(mg/L)       w21011-ZsRtd

     总氮实时浓度(mg/L)          w21001-Rtd
     总氮实时折算浓度(mg/L)       w21001-ZsRtd

     PH值实时数据(无量纲)        w01001-Rtd
     废水流量实时数据(m3/h)      c060605-Rtd
     化学需氧量排放量（kg）       c060601-Rtd
     氨氮排放量（kg）           c060602-Rtd
     总磷排放量（kg）           c060603-Rtd
     总氮排放量（kg）           c060604-Rtd
     * @param deviceId
     * @param dataBlock
     */
    public static void createWasteWaterMinuteData(String deviceId, StringBuilder dataBlock){
        //1/2-化学需氧量实时浓度(mg/L)     w01018-Rtd 化学需氧量实时折算浓度(mg/L)  w01018-ZsRtd
        dataBlock.append(getDataMinuteWasteWaterTwo(deviceId,"w01018"));
        //3/4-氨氮实时浓度(mg/L)          w21003-Rtd
        //     氨氮实时折算浓度(mg/L)       w21003-ZsRtd
        dataBlock.append(getDataMinuteWasteWaterTwo(deviceId,"w21003"));
        //5/6总磷实时数据(mg/L)          w21011-Rtd
        //总磷实时折算浓度(mg/L)       w21011-ZsRtd
        dataBlock.append(getDataMinuteWasteWaterTwo(deviceId,"w21011"));
        //7/8总氮实时浓度(mg/L)          w21001-Rtd
        //总氮实时折算浓度(mg/L)       w21001-ZsRtd
        dataBlock.append(getDataMinuteWasteWaterTwo(deviceId,"w21001"));
        //9-PH值实时数据
        dataBlock.append(getDataMinute(deviceId,"w01001-Rtd"));
        //10-废水流量实时数据(m3/h) c060605-Rtd
        dataBlock.append(getDataMinute(deviceId,"c060605-Rtd"));
        //11-化学需氧量排放量（kg） c060601-Rtd
        dataBlock.append(getDataMinute(deviceId,"c060601-Rtd"));
        //12-氨氮排放量（kg） c060602-Rtd
        dataBlock.append(getDataMinute(deviceId,"c060602-Rtd"));
        //13-总磷排放量（kg） c060603-Rtd
        dataBlock.append(getDataMinute(deviceId,"c060603-Rtd"));
        //14-总氮排放量（kg） c060604-Rtd
        dataBlock.append(getDataMinute(deviceId,"c060604-Rtd").replace(";",""));

        //处理完毕数据后清空
        DataConfig.MINUTE_DATA.get(deviceId,"w01018-Rtd").clear();
        DataConfig.MINUTE_DATA.get(deviceId,"w01018-ZsRtd").clear();

        DataConfig.MINUTE_DATA.get(deviceId,"w21003-Rtd").clear();
        DataConfig.MINUTE_DATA.get(deviceId,"w21003-ZsRtd").clear();

        DataConfig.MINUTE_DATA.get(deviceId,"w21011-Rtd").clear();
        DataConfig.MINUTE_DATA.get(deviceId,"w21011-ZsRtd").clear();

        DataConfig.MINUTE_DATA.get(deviceId,"w21001-Rtd").clear();
        DataConfig.MINUTE_DATA.get(deviceId,"w21001-ZsRtd").clear();

        DataConfig.MINUTE_DATA.get(deviceId,"w01001-Rtd").clear();
        DataConfig.MINUTE_DATA.get(deviceId,"c060605-Rtd").clear();
        DataConfig.MINUTE_DATA.get(deviceId,"c060601-Rtd").clear();
        DataConfig.MINUTE_DATA.get(deviceId,"c060602-Rtd").clear();
        DataConfig.MINUTE_DATA.get(deviceId,"c060603-Rtd").clear();
        DataConfig.MINUTE_DATA.get(deviceId,"c060604-Rtd").clear();


        log.info("十分钟数据：{}", JSONUtil.toJsonStr(DataConfig.MINUTE_DATA));
    }
    /**
     *
     * @param deviceId
     * @param id
     * @return
     */
    public static String getDataMinuteWasteWaterTwo(String deviceId, String id){

        //a21026-Rtd  a21026-ZsRtd
        String idRtd = id+"-Rtd";
        String idZsRtd = id+"-ZsRtd";
        List<Double> rtdDataList = DataConfig.MINUTE_DATA.get(deviceId,idRtd);
        List<Double> rtdHourData = DataConfig.HOUR_DATA.get(deviceId,idRtd)==null?new ArrayList<>():DataConfig.HOUR_DATA.get(deviceId,idRtd);
        rtdHourData.addAll(rtdDataList);
        DataConfig.HOUR_DATA.put(deviceId,idRtd,rtdHourData);

        List<Double> zsRtdDataList = DataConfig.MINUTE_DATA.get(deviceId,idZsRtd);
        List<Double> zsRtdHourData = DataConfig.HOUR_DATA.get(deviceId,idZsRtd)==null?new ArrayList<>():DataConfig.HOUR_DATA.get(deviceId,idZsRtd);
        zsRtdHourData.addAll(zsRtdDataList);
        DataConfig.HOUR_DATA.put(deviceId,idZsRtd,zsRtdHourData);

        //得到和
        double cou = rtdDataList.stream().mapToDouble( Double :: valueOf ).sum();
        //得到平均数
        double avg = rtdDataList.stream().mapToDouble( Double :: valueOf ).average().getAsDouble();
        //得到最小值
        double min = rtdDataList.stream().mapToDouble( Double :: valueOf ).min().getAsDouble();
        //得到最大值
        double max = rtdDataList.stream().mapToDouble( Double :: valueOf ).max().getAsDouble();

        //得到平均数
        double zsAvg = zsRtdDataList.stream().mapToDouble( Double :: valueOf ).average().getAsDouble();
        //得到最小值
        double zsMin = zsRtdDataList.stream().mapToDouble( Double :: valueOf ).min().getAsDouble();
        //得到最大值
        double zsMax = zsRtdDataList.stream().mapToDouble( Double :: valueOf ).max().getAsDouble();
        /**
         * 算十分钟模拟数据：##1000ST=32;CN=2051;PW=123456;MN=DW0001;CP=&&DataTime=20230613173000;
         * w01018-Cou=99.6000,w01018-Min=10.7000,w01018-Avg=19.9200,w01018-Max=25.6000,w01018-ZsAvg=19.9200;
         * w21003-Cou=1.7130,w21003-Min=0.2710,w21003-Avg=0.3426,w21003-Max=0.3620,w21003-ZsAvg=0.5139;
         * w21011-Cou=4.2200,w21011-Min=0.5000,w21011-Avg=0.8440,w21011-Max=1.4500,w21011-ZsAvg=1.2660;
         * w21001-Cou=39.1400,w21001-Min=4.8200,w21001-Avg=7.8280,w21001-Max=11.8000,w21001-ZsAvg=11.7420;w01001-Rtd-Cou=36.2500,
         * w01001-Rtd-Min=7.0000,w01001-Rtd-Avg=7.2500,w01001-Rtd-Max=7.4300;c060605-Rtd-Cou=5811.9667,
         * c060605-Rtd-Min=980.6667,c060605-Rtd-Avg=1162.3933,c060605-Rtd-Max=1371.5903;
         * c060601-Rtd-Cou=0.0313,c060601-Rtd-Min=0.0039,c060601-Rtd-Avg=0.0063,
         * c060601-Rtd-Max=0.0073;c060602-Rtd-Cou=0.0056,c060602-Rtd-Min=0.0008,
         * c060602-Rtd-Avg=0.0011,c060602-Rtd-Max=0.0014;c060603-Rtd-Cou=0.0014,
         * c060603-Rtd-Min=0.0002,c060603-Rtd-Avg=0.0003,c060603-Rtd-Max=0.0005;
         * c060604-Rtd-Cou=0.0118,c060604-Rtd-Min=0.0020,c060604-Rtd-Avg=0.0024,
         * c060604-Rtd-Max=0.0028&&E2C1
         */
        String data = id+"-Cou="+ getValue(cou) +","+ id +"-Min="+ getValue(min) +","+ id +"-Avg="+ getValue(avg )+","+ id +"-Max="+ getValue(max) +",";
        //String zsData= id +"-ZsMin="+ getValue(zsMin) +","+ id +"-ZsAvg="+ getValue(zsAvg) +","+ id +"-ZsMax="+ getValue(zsMax) +";";
        String zsData= id +"-ZsAvg="+ getValue(zsAvg) +";";
        //String zsData= id +"-ZsAvg="+ zsAvg +";";

        return (data.concat(zsData));
    }

    public static String getDataHour(String deviceId, String ID){
        List<Double> rtdDataList = DataConfig.HOUR_DATA.get(deviceId,ID);
        //得到和
        double cou = rtdDataList.stream().mapToDouble( Double :: valueOf ).sum();
        //得到平均数
        double avg = rtdDataList.stream().mapToDouble( Double :: valueOf ).average().getAsDouble();
        //得到最小值
        double min = rtdDataList.stream().mapToDouble( Double :: valueOf ).min().getAsDouble();
        //得到最大值
        double max = rtdDataList.stream().mapToDouble( Double :: valueOf ).max().getAsDouble();
        String finalId = ID.replace("-Rtd","");
        String data = finalId+"-Cou="+ getValue(cou) +","+ finalId +"-Min="+ getValue(min) +","+ finalId +"-Avg="+ getValue(avg) +","+ finalId +"-Max="+ getValue(max)+";";
        return data;
    }

    public static String getDataHourTwo(String deviceId, String id){

        String idRtd = id+"-Rtd";
        String idZsRtd = id+"-ZsRtd";

        List<Double> rtdDataList = DataConfig.HOUR_DATA.get(deviceId,idRtd);
        //得到和
        double cou = rtdDataList.stream().mapToDouble( Double :: valueOf ).sum();
        //得到平均数
        double avg = rtdDataList.stream().mapToDouble( Double :: valueOf ).average().getAsDouble();
        //得到最小值
        double min = rtdDataList.stream().mapToDouble( Double :: valueOf ).min().getAsDouble();
        //得到最大值
        double max = rtdDataList.stream().mapToDouble( Double :: valueOf ).max().getAsDouble();


        List<Double> zsRtdDataList = DataConfig.HOUR_DATA.get(deviceId,idZsRtd);
        //得到平均数
        double zsAvg = zsRtdDataList.stream().mapToDouble( Double :: valueOf ).average().getAsDouble();
        //得到最小值
        double zsMin = zsRtdDataList.stream().mapToDouble( Double :: valueOf ).min().getAsDouble();
        //得到最大值
        double zsMax = zsRtdDataList.stream().mapToDouble( Double :: valueOf ).max().getAsDouble();

        String data = id+"-Cou="+ getValue(cou) +","+ id +"-Min="+ getValue(min) +","+ id +"-Avg="+ getValue(avg )+","+ id +"-Max="+ getValue(max) +",";
        //String zsData= id +"-ZsMin="+ getValue(zsMin) +","+ id +"-ZsAvg="+ getValue(zsAvg) +","+ id +"-ZsMax="+ getValue(zsMax) +";";
        String zsData= id +"-ZsAvg="+ getValue(zsAvg)  +";";
        return (data.concat(zsData));
    }
    public static void createWasteWaterHourData(String deviceId, StringBuilder dataBlock){
        //1/2-化学需氧量实时浓度(mg/L)     w01018-Rtd 化学需氧量实时折算浓度(mg/L)  w01018-ZsRtd
        dataBlock.append(getDataHourTwo(deviceId,"w01018"));
        //3/4-氨氮实时浓度(mg/L)          w21003-Rtd
        //     氨氮实时折算浓度(mg/L)       w21003-ZsRtd
        dataBlock.append(getDataHourTwo(deviceId,"w21003"));
        //5/6总磷实时数据(mg/L)          w21011-Rtd
        //总磷实时折算浓度(mg/L)       w21011-ZsRtd
        dataBlock.append(getDataHourTwo(deviceId,"w21011"));
        //7/8总氮实时浓度(mg/L)          w21001-Rtd
        //总氮实时折算浓度(mg/L)       w21001-ZsRtd
        dataBlock.append(getDataHourTwo(deviceId,"w21001"));
        //9-PH值实时数据
        dataBlock.append(getDataHour(deviceId,"w01001-Rtd"));
        //10-废水流量实时数据(m3/h) c060605-Rtd
        dataBlock.append(getDataHour(deviceId,"c060605-Rtd"));
        //11-化学需氧量排放量（kg） c060601-Rtd
        dataBlock.append(getDataHour(deviceId,"c060601-Rtd"));
        //12-氨氮排放量（kg） c060602-Rtd
        dataBlock.append(getDataHour(deviceId,"c060602-Rtd"));
        //13-总磷排放量（kg） c060603-Rtd
        dataBlock.append(getDataHour(deviceId,"c060603-Rtd"));
        //14-总氮排放量（kg） c060604-Rtd
        dataBlock.append(getDataHour(deviceId,"c060604-Rtd").replace(";",""));

        //处理完毕数据后清空
        DataConfig.HOUR_DATA.get(deviceId,"w01018-Rtd").clear();
        DataConfig.HOUR_DATA.get(deviceId,"w01018-ZsRtd").clear();

        DataConfig.HOUR_DATA.get(deviceId,"w21003-Rtd").clear();
        DataConfig.HOUR_DATA.get(deviceId,"w21003-ZsRtd").clear();

        DataConfig.HOUR_DATA.get(deviceId,"w21011-Rtd").clear();
        DataConfig.HOUR_DATA.get(deviceId,"w21011-ZsRtd").clear();

        DataConfig.HOUR_DATA.get(deviceId,"w21001-Rtd").clear();
        DataConfig.HOUR_DATA.get(deviceId,"w21001-ZsRtd").clear();

        DataConfig.HOUR_DATA.get(deviceId,"w01001-Rtd").clear();
        DataConfig.HOUR_DATA.get(deviceId,"c060605-Rtd").clear();
        DataConfig.HOUR_DATA.get(deviceId,"c060601-Rtd").clear();
        DataConfig.HOUR_DATA.get(deviceId,"c060602-Rtd").clear();
        DataConfig.HOUR_DATA.get(deviceId,"c060603-Rtd").clear();
        DataConfig.HOUR_DATA.get(deviceId,"c060604-Rtd").clear();

        log.info("小时数据：{}",JSONUtil.toJsonStr(DataConfig.HOUR_DATA));
    }

    public static String getDataMinute(String deviceId, String ID){
        List<Double> rtdDataList = DataConfig.MINUTE_DATA.get(deviceId,ID);

        List<Double> hourData = DataConfig.HOUR_DATA.get(deviceId,ID)==null?new ArrayList<>():DataConfig.HOUR_DATA.get(deviceId,ID);
        hourData.addAll(rtdDataList);
        DataConfig.HOUR_DATA.put(deviceId,ID,hourData);
        //得到和
        double cou = rtdDataList.stream().mapToDouble( Double :: valueOf ).sum();
        //得到平均数
        double avg = rtdDataList.stream().mapToDouble( Double :: valueOf ).average().getAsDouble();
        //得到最小值
        double min = rtdDataList.stream().mapToDouble( Double :: valueOf ).min().getAsDouble();
        //得到最大值
        double max = rtdDataList.stream().mapToDouble( Double :: valueOf ).max().getAsDouble();
        String finalId = ID.replace("-Rtd","");
        String data = finalId+"-Cou="+ getValue(cou) +","+ finalId +"-Min="+ getValue(min) +","+ finalId +"-Avg="+ getValue(avg) +","+ finalId +"-Max="+ getValue(max) +";";
        return data;
    }
    private static String getValue(double value){
        String v = value+"";
        return getCellValue(v);
    }
}
